﻿package se.penselnsvag.bookdb.tech.log.imp{
	import se.penselnsvag.bookdb.tech.log.LoggerInterface;
	
	

/**
* TraceLogger,
*
* Log output public class, writing to Trace().
*
* Version: 1.1 
* Author:mattias.anstrand@loveone.se
* History:
*
* 1.1 - clone added:  2006-04-11
* 1.0 - created: 2006-02-??
*/

public class Log4jLoggerImp extends BaseLoggerImp implements LoggerInterface
{
	public function Log4jLoggerImp(logLevel:Number)
	{
		super(logLevel, null);
	}

	private var _className:String;
	
	public function clone() :Log4jLoggerImp {
		var clone:Log4jLoggerImp = new Log4jLoggerImp(logLevel);
		clone.setClassName(_className);
		return clone;
	}
	

	public function setClassName(cn:String):void {
		_className=cn;
	}

	
	
	protected override function tr(message:Object, level:int):void {
		if(logLevel<level )
			return;
			
			var d:Date = new Date();
			trace(	zeroPad(d.getHours())+":"+
					zeroPad(d.getMinutes())+":"+
					zeroPad(d.getSeconds())+":"+
					zeroPad(d.getMilliseconds())+
					" ["+this._className+"] "+(message==null ? "null" : message.toString()));
	}
	
	
	
	private function zeroPad(n:Number):String {
		if (n<=9)
			return "0"+n;
		else
			return ""+n;
	}
	
}
}